#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @time: 2022-08-04 21:17:07
# @author: 鹰眼测试
"""
对目录（文件夹）进行操作的方法，例如增、删、改、查
"""
import shutil
import os


# 判断文件夹是否存在
def check_folder(folder):
    """
    :param folder: 目录路径
    :return: 目录存在返回True，不存在返回False
    """
    if os.path.exists(folder):
        return True
    else:
        return False


# 创建文件夹
def create_folder(folder):
    """
    :param folder: 目录路径
    :return: None
    """
    if check_folder(folder):
        raise FileExistsError(f"{folder} 已存在")
    else:
        os.mkdir(folder)


# 删除文件夹
def delete_folder(folder):
    """
    :param folder: 目录路径
    :return:
    """
    if not check_folder(folder):
        raise FileNotFoundError(f"{folder} 不存在")
    else:
        shutil.rmtree(folder)


# 复制文件夹
def copy_folder(folder, target_path):
    """
    :param folder: 目录路径
    :param target_path: 目标路径
    :return:
    """
    if not check_folder(folder):
        raise FileNotFoundError(f"{folder} 不存在")
    elif check_folder(target_path):
        raise FileExistsError(f"{target_path} 已存在")
    else:
        shutil.copytree(folder, target_path)
